package me.szlx.thing.parser;

import me.szlx.thing.ThingCreator;
import me.szlx.thing.TraitCreator;

/**
 * Created by shenzhilin on 2017-4-25.
 */
public class ThingParserConfig {
    private String format;
    private ThingCreator thingCreator;
    private TraitCreator traitCreator;
    private String prefix;

    static public ThingParserConfig newInstance() {
        return new ThingParserConfig(null);
    }

    private ThingParserConfig(ThingParserConfig config) {
        if (config != null) {
            this.format = config.format;
            this.thingCreator = config.thingCreator;
            this.traitCreator = config.traitCreator;
            this.prefix = config.prefix;
        }
    }

    public ThingParserConfig format(String format) {
        ThingParserConfig config = new ThingParserConfig(this);
        config.format = format;
        return config;
    }

    public ThingParserConfig thingCreator(ThingCreator thingCreator) {
        ThingParserConfig config = new ThingParserConfig(this);
        config.thingCreator = thingCreator;
        return config;
    }

    public ThingParserConfig traitCreator(TraitCreator traitCreator) {
        ThingParserConfig config = new ThingParserConfig(this);
        config.traitCreator = traitCreator;
        return config;
    }

    public ThingParserConfig prefix(String prefix) {
        ThingParserConfig config = new ThingParserConfig(this);
        config.prefix = prefix;
        return config;
    }

    /**
     * 资源格式，当前支持：properties、yml（yaml）和 conf
     * @return 资源格式。
     */
    public String getFormat() {
        return format;
    }

    public ThingCreator getThingCreator() {
        return thingCreator;
    }

    public TraitCreator getTraitCreator() {
        return traitCreator;
    }

    public String getPrefix() {
        return prefix;
    }
}
